package com.aiju.cash.ui.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.core.api.RevenueApi;
import com.aiju.cash.core.api.SimpleCallback;
import com.aiju.cash.ui.main.entity.Revenue;
import com.aiju.cash.util.GsonHelper;
import com.aiju.utils.DateUtil;
import com.aiju.widgit.layout.SettingItemTextView;

/**
 * @author: 佐为
 * @date: 2017-01-04 14:21
 * @version: V1.0
 * @Description: 收入
 */
public class RevenueActivity extends BaseTitleActivity implements View.OnClickListener {

    //总价
    private SettingItemTextView totalTextView;

    //今日、七天、三十天
    private SettingItemTextView todayTextView;
    private SettingItemTextView sevenTextView;
    private SettingItemTextView thirtyTextView;

    //本月日期
    private TextView dateTextView;

    //微信、支付宝、QQ钱包、现金、退款
    private SettingItemTextView zhifTextView, wechatTextView, xjTextView;
    private SettingItemTextView qqTextView, tkTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_revenue);
        setCenterTitle("我的收入");

        totalTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_price);
        todayTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_today);
        sevenTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_seven);
        thirtyTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_thirty);
        zhifTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_zhifu);
        wechatTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_wechat);
        xjTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_xj);
        dateTextView = (TextView) findViewById(R.id.tv_revenue_date);
        qqTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_qq);
        tkTextView = (SettingItemTextView) findViewById(R.id.tv_revenue_tk);

        todayTextView.setOnClickListener(this);
        sevenTextView.setOnClickListener(this);
        thirtyTextView.setOnClickListener(this);
        zhifTextView.setOnClickListener(this);
        wechatTextView.setOnClickListener(this);
        xjTextView.setOnClickListener(this);
        qqTextView.setOnClickListener(this);
        tkTextView.setOnClickListener(this);

        mDialogHelper.showLoadingProgressDialog();
        new RevenueApi().list(mUser.getToken(), mUser.getShop().getStoreId(), new SimpleCallback(mDialogHelper) {
            @Override
            protected void onDataSuccess(String data) {
                bindView(GsonHelper.convertEntity(data, Revenue.class));
            }
        });
    }

    private void bindView(Revenue revenue) {
        if (revenue == null) {
            return;
        }
        totalTextView.setRightText(revenue.getTotalIncome());
        todayTextView.setRightText(revenue.getToday());
        sevenTextView.setRightText(revenue.getSevenDay());
        thirtyTextView.setRightText(revenue.getThirtyDay());
        zhifTextView.setRightText(revenue.getZfb());
        wechatTextView.setRightText(revenue.getWx());
        xjTextView.setRightText(revenue.getXj());
        dateTextView.setText(DateUtil.getCurrentDate(DateUtil.dateFormatMY));
        qqTextView.setRightText(revenue.getQq());
        tkTextView.setRightText(revenue.getTk());
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, RevenueListActivity.class);
        intent.putExtra("type", v.getTag().toString());
        startActivity(intent);
    }
}
